package com.beit.mybatis.demo.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Configuration
public class CustomMybatisConfiguration {

    @Bean
    @ConditionalOnProperty(value = "mybatis-plus.configuration.map-underscore-to-camel-case", havingValue = "true")
    public ConfigurationCustomizer configurationCustomizer() {
        // https://baomidou.com/reference/question/
        // Map 查询结果下划线自动转驼峰
        return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
    }

    /**
     * @return 分页插件
     * @see <a href="https://baomidou.com/plugins/pagination/">分页插件</a>
     */
    @Bean
    @Order(100)
    public PaginationInnerInterceptor paginationInnerInterceptor() {
        return new PaginationInnerInterceptor();
    }
}
